﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufDynamicPanelBase.h"
#include "GnufPallet.h"
#include "GnufInfo.h"
#include "GnufINotificationCenterEventArgs.h"

/// \file GnufDynamicPanel.h
/// \brief 动态面板

namespace gnuf {

    class Block;
    class ValueInputSet;
    class NameValuePairs;
    class ButtonEx;
    class DropDownBoard;

    /// \brief Block 构建器
    /// \see Block IToolbarWatcher ButtonEx
    class GNUF_BASE_EXPORT BlockBuilder final : public BlockBuilderBase
    {
    public:
        BlockBuilder(Block * block, IToolbarWatcher * toolbarWatcher, EButtonDisplayStyle style);
        virtual ~BlockBuilder();
    };

    /// \brief 动态面板
    /// \see Component IItemEventHandler
    class GNUF_BASE_EXPORT DynamicPanel 
        : public DynamicPanelBase
    {
        DEFINE_CAST_DERIVED(DynamicPanel, DynamicPanelBase)
        CANNOT_COPY_OR_ASSIGN(DynamicPanel)
    public:
        DynamicPanel(
            const std::wstring & key,
            const gcmp::UniqueString * uniqueKey,
            const std::wstring & caption,
            EItemType type,
            bool wantSwitchButtonStyle = false);
        virtual ~DynamicPanel();

        void setCaption(const std::wstring &);
        const std::wstring & caption() const { return m_caption; }

        gcmp::OwnerPtr< BlockBuilder > blockBuilder();
        void setValueInputSet(ValueInputSet *);

        // Set/Get the user data.
        inline void setUserData(const gcmp::Any& val) { m_userData = val; }
        inline const gcmp::Any& userData() const { return m_userData; }

        // Set/Get the ID of the context in which the dynamic panel lives.
        void setContextId(const std::wstring & val);
        const std::wstring & contextId() const { return m_contextId; }

        void onRefreshStatus();

    protected:
        // Inherits from ArrangementAreaContent...
        virtual QWidget * qtWidget() override;
        virtual void onPostOpacityChanged() override;
        virtual void onPostConnectedWithArrangementArea() override;
        virtual void onPreDisconnectedFromArrangementArea() override;
        virtual void onPostGeometryChanged() override;
        virtual void onEvent(ArrangementAreaEvent*) override;

        // Inherits from Component...
        virtual void initialize(Toolbar *) override;
        virtual gcmp::OwnerPtr<QtToolbar> createQtToolBar(Toolbar*) override;
        // Inherits from IItemEventHandler...
        virtual bool onPreClicked(Item *) override;
        virtual void onHeightChanged(Toolbar*, int) override;

    private:
        Item * getItem(const EItemType);
        std::wstring m_caption;
        const EItemType m_type;
        gcmp::Any m_userData;
        std::wstring m_contextId;
    };

    class GNUF_BASE_EXPORT GetDynamicPanelEventArgs final
        : public INotificationCenterEventArgs
    {
        DEFINE_CAST_DERIVED(GetDynamicPanelEventArgs, INotificationCenterEventArgs)
        CANNOT_COPY_OR_ASSIGN(GetDynamicPanelEventArgs)
    public:
        GetDynamicPanelEventArgs();

        void add(gcmp::OwnerPtr<DynamicPanel> &);
        void take(std::list< gcmp::OwnerPtr< DynamicPanel > > &);
    private:
        std::list< gcmp::OwnerPtr< DynamicPanel > > m_list;
    };

}
